<template>
  <div>
    <f-table ref='table' rowKey='paymentId'  :columns='columns' :scroll='scroll'  :multiple='true' :operator='operator' :rowSelection='rowSelection' :showMultipleBtn='true' :params='queryParam' :api='api.payment' handler='settlePaymentPageListHandler'>
        <span slot='paymentState' slot-scope='text, record, index'>
            <a-tag color='#87d068' v-if='text==0'>未提交</a-tag>
             <a-tag color='#108ee9' v-if="text==1&&record.taskName=='出纳支付'" @click='processImg(record)'>{{ record.taskName }}</a-tag>
             <a-tag color='#87d068' v-if="text==1&&record.taskName!='出纳支付'" @click='processImg(record)'>{{ record.taskName }}</a-tag>
            <a-tag color='#f50' v-if='text==2' @click='processImg(record)'>已结算</a-tag>
        </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='startProcess(record.paymentId)' v-if='record.paymentState==0'>提交</a>
            <a @click='completeTask(record)' v-if="record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__'">提交</a>
            <a-divider type='vertical' v-if="record.paymentState==0||(record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__')" />
            <a @click="$refs.drawer.showDrawer(record,'form2')">详情</a>
            <a-divider type='vertical' />
          </template>
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
               <a-menu-item>
                <a href='javascript:;' @click='$refs.orderInfoDrawer.showDrawer(record)'>订单详情</a>
              </a-menu-item>
               <a-menu-item v-if='record.paymentState!=0'>
                <a href='javascript:;' @click='processImg(record)'>审批进度</a>
              </a-menu-item>
               <a-menu-item v-if='record.companyId==4 &&  record.taskName=="出纳支付"'>
                <a href='javascript:;' @click='printPayment(record)'>资金支付单</a>
              </a-menu-item>
                <a-menu-item v-if='record.companyId!=4'>
                <a href='javascript:;' @click='printPayment(record)'>资金支付单</a>
              </a-menu-item>
              <a-menu-item v-if="record.paymentState==0||(record.taskDefinitionKey&&record.taskDefinitionKey=='__initiator__')">
                <a href='javascript:;' @click="$refs.table.del(record,{handlerName:'settlePaymentDeleteHandler',processInstanceId:record.processInstanceId})">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
    </f-table>
    <settle-drawer ref='drawer' @success='onLoad'></settle-drawer>
    <process-image ref='processImg' v-if='processImageVisible' :visible.sync='processImageVisible' :processInstanceId='processInstanceId'></process-image>
    <print-modal ref='printModal'></print-modal>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
  </div>
</template>
<script>
import api from "./../js/api"
import ProcessImage from "../../../flowable/process/process_image"
import PrintModal from "../print/print_modal"
import SettleDrawer from "./settle_drawer"
import OrderInfoDrawer from "@/views/module/business/order/order_info_drawer"

export default {
  name: "CbreturnYes",
  components: {
    OrderInfoDrawer,
    SettleDrawer,
    ProcessImage,
    PrintModal
  },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: "导出结算明细",
      icon: "transaction",
      batch: true,
      that: this,
      handler: function(table, that) {
        let selectIds = table.selectedRowKeys
        if (selectIds.length > 0) {
          that.http.exportExcel(that, {
            url: that.api.bod.exportSettleDetails,
            data: {
              handlerName:'yesSettlePageListHandler',
              paymentIds: selectIds.join(","),
              columns:"[{name:'单号',key:'orderNo'},{name:'发货日期',key:'sendDate'},{name:'供货方',key:'supplierName'},{name:'购货方',key:'customName'},{name:'商品名称',key:'drugsName'},{name:'规格',key:'drugsSpec'},{name:'数量',key:'saleNum'},{name:'单价',key:'salePrice'},{name:'发货算额',isStatistics:true,key:'saleAmount'},{name:'回款金额',isStatistics:true,key:'returnAmount'},{name:'回款日期',key:'returnDate'},{name:'应结金额',isStatistics:true,key:'settleAmount'},{name:'应结金额2',isStatistics:true,key:'settleAmount2'},{name:'应结金额3',isStatistics:true,key:'settleAmount3'},{name:'应退保证金',isStatistics:true,key:'customBond'}]"
            }
          })
        } else {
          that.$message.error("请选择结算明细")
        }
      }
    })
    operator.push({
      name: "批量提交",
      icon: "transaction",
      batch: true,
      that: this,
      handler: function(table, that) {
        let selectIds = table.selectedRowKeys
        if (selectIds.length > 0) {
          that.startProcess(selectIds.join(","));
        } else {
          that.$message.error("请选择需要提交审批的订单")
        }
      }
    })
    return {
      api: Object.assign(api, this.api),
      //列表初始化查询参数
      queryParam: {
        auth:1
      },
      scroll: { x: true },
      processImageVisible: false,
      // 表头
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "left",
          fixed: "left",
          customRender: (text, record, index) => index + 1
        },
        {
          title: "操作",
          align: "left",
          width: "150px",
          fixed: "left",
          scopedSlots: { customRender: "action" }
        },
        {
          title: "单号",
          align: "left",
          width: "140px",
          fixed: "left",
          dataIndex: "paymentNo"
        },
        {
          title: "状态",
          align: "left",
          width: "120px",
          sorter: true,
          dataIndex: "paymentState",
          scopedSlots: { customRender: "paymentState" },
          filters: [
            { text: "未提交", value: 0 },
            { text: "未办结", value: 1 },
            { text: "已退款", value: 2 }
          ]
        },
        {
          title: "部门",
          align: "left",
          width: "100px",
          sorter: true,
          dataIndex: "deptName"
        },
        {
          title: "负责人",
          align: "left",
          width: "80px",
          dataIndex: "deptManagerName"
        },
        {
          title: "购货方",
          align: "left",
          ellipsis: true,
          width: "170px",
          dataIndex: "customName"
        },
        {
          title: "收款人",
          align: "left",
          width: "100px",
          dataIndex: "saleManName"
        },
        {
          title: "收款银行",
          align: "center",
          ellipsis: true,
          width: "170px",
          dataIndex: "bankName"
        },
        {
          title: "收款账户",
          align: "left",
          width: "170px",
          ellipsis: true,
          dataIndex: "bankNo"
        },
        {
          title: "结算金额",
          align: "left",
          width: "100px",
          dataIndex: "amount"
        },
        {
          title: "申请人",
          align: "center",
          width: "80px",
          sorter: true,
          ellipsis: true,
          dataIndex: "nickName"
        },
        {
          title: "申请日期",
          align: "left",
          sorter: true,
          width: "100px",
          dataIndex: "amountDate"
        },
        {
          title: "支付日期",
          align: "left",
          sorter: true,
          width: "120px",
          dataIndex: "payDate"
        },

        {
          title: "支付人",
          align: "left",
          width: "100px",
          ellipsis: true,
          dataIndex: "payUserName"
        },
        {
          title: "创建日期",
          align: "left",
          sorter: true,
          width: "100px",
          dataIndex: "createTime"
        }
      ],
      operator: operator
    }
  },
  computed: {
    rowSelection() {
      return {
        getCheckboxProps: record => ({
          props: {
            disabled: record.paymentState!=0, // Column configuration not to be checked
            name: record.paymentState,
          },
        }),
      };
    },

  },
  methods: {
    //流程图
    processImg(order) {
      this.processInstanceId = order.processInstanceId
      this.processImageVisible = true
    },
    //重新提交
    completeTask(paymentId) {
      this.http.confirm(this, {
        content: "确认提交审批吗?",
        url: api.tasktodo.complete,
        requestBody: true,
        data: {
          taskId: paymentId.taskId
        },
        success: function(me, data) {
          me.$refs.table.refresh()
        }
      })
    },
    //提交审批
    startProcess(paymentId) {
      this.http.confirm(this, {
        content: "确认提交审批吗?",
        url: api.processInstance.start,
        requestBody: true,
        data: {
          handlerName: "paymentPayStartProcessHandler",
          businessKey: paymentId
        },
        success: function(me, data) {
          me.$refs.table.refresh()
        }
      })
    },
    //刷新列表
    onLoad() {
      this.$refs.table.refresh()
    },
    //打印
    printPayment(record) {
      this.$refs["printModal"].open(record.paymentId, 2, "Settle")
    },
    //列表查询
    searchTable(searchParams) {
      searchParams.paymentState = 1
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    }
  }
}
</script>
